public class Solution1094 {
    public boolean carPooling(int[][] trips, int capacity) {
        int[] f=new int[1005];
        for (int[] trip : trips) {
            f[trip[1]]+=trip[0];
            f[trip[2]]-=trip[0];
        }
        int ans=0;
        for (int i=0;i<=1000;i++){
            ans=ans+f[i];
            if (ans>capacity){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1094().carPooling(new int[][]{{2,1,5},{3,3,7}},4));
    }
}
